<html>
<head><meta charset="utf-8"><title>What is &quot;uninhabited&quot; · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20.22uninhabited.22.html">What is &quot;uninhabited&quot;</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="197060127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20%22uninhabited%22/near/197060127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Derek <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20.22uninhabited.22.html#197060127">(May 10 2020 at 15:03)</a>:</h4>
<p>I'm reading document, I see it use word  "uninhabited", what exactly "uninhabited" means here. e.g. for panic_if_uninhabited, how to trigger a panic in following example?  Thanks. </p>
<div class="codehilite"><pre><span></span><code><span class="cp">#![feature(core_intrinsics)]</span><span class="w"></span>
<span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">intrinsics</span><span class="p">;</span><span class="w"></span>
<span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">mem</span>::<span class="n">ManuallyDrop</span><span class="p">;</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">intrinsics</span>::<span class="n">panic_if_uninhabited</span>::<span class="o">&lt;</span><span class="kt">i32</span><span class="o">&gt;</span><span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="n">intrinsics</span>::<span class="n">panic_if_uninhabited</span>::<span class="o">&lt;</span><span class="n">ManuallyDrop</span><span class="o">&lt;</span><span class="kt">i32</span><span class="o">&gt;&gt;</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;Hello, world!&quot;</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="197060274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20%22uninhabited%22/near/197060274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20.22uninhabited.22.html#197060274">(May 10 2020 at 15:07)</a>:</h4>
<p>"uninhabited" means a type with no valid values, e.g., <code>!</code> or <code>enum Empty {}</code></p>



<a name="197061035"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20%22uninhabited%22/near/197061035" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Derek <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20.22uninhabited.22.html#197061035">(May 10 2020 at 15:22)</a>:</h4>
<p>Thanks, I got panic enum Empty. </p>
<div class="codehilite"><pre><span></span><code><span class="cp">#![feature(core_intrinsics)]</span><span class="w"></span>
<span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">intrinsics</span><span class="p">;</span><span class="w"></span>

<span class="w">  </span><span class="k">enum</span> <span class="nc">Empty</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="w">  </span><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">      </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">          </span><span class="n">intrinsics</span>::<span class="n">panic_if_uninhabited</span>::<span class="o">&lt;</span><span class="n">Empty</span><span class="o">&gt;</span><span class="p">();</span><span class="w"></span>
<span class="w">   </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>But with !, got a compile error, </p>
<div class="codehilite"><pre><span></span><code>$ cargo +nightly run
error<span class="o">[</span>E0658<span class="o">]</span>: The <span class="sb">`</span>!<span class="sb">`</span> <span class="nb">type</span> is experimental
   <span class="p">|</span>
<span class="m">9</span> <span class="p">|</span>         intrinsics::panic_if_uninhabited::&lt;!&gt;<span class="o">()</span><span class="p">;</span>
</code></pre></div>



<a name="197061276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20%22uninhabited%22/near/197061276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20.22uninhabited.22.html#197061276">(May 10 2020 at 15:25)</a>:</h4>
<p>When you want to use <code>!</code> as a type, you need to enable <code>#![feature(never_type)]</code>.</p>



<a name="197061371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20%22uninhabited%22/near/197061371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Derek <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20.22uninhabited.22.html#197061371">(May 10 2020 at 15:26)</a>:</h4>
<p><span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span> <span class="user-mention" data-user-id="116118">@Matthew Jasper</span> <span class="user-mention" data-user-id="133247">@bjorn3</span> Thanks!!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>